home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / SMan / MorphOS / Source / ULP6mos.asm < prev    next >
Encoding:
Assembly Source File  |  2001-03-09  |  4.8 KB  |  197 lines

  1.  
  2. #    r0        volatile, may be used by function linkage
  3. #    r1        stack pointer
  4. #    r2        table of contents register
  5. #    r3    .. r4    volatile, pass 1st - 2nd int args, return 1st - 2nd ints
  6. #    r5  .. r10    volatile, pass 3rd - 8th int args
  7. #    r11        volatile, pass static chain if language needs it
  8. #    r12        volatile, used by dyn linker, exception handling
  9. #    r13 .. r31    saved
  10.  
  11.  
  12.  
  13. #    f0        volatile
  14. #    f1  .. f4    volatile, pass 1st - 4th float args, return 1st - 4th floats
  15. #    f5  .. f13    volatile, pass 5th - 13th float args
  16. #    f14 .. f31    saved
  17.  
  18. #    Use r23    as CurCnt
  19. #    Use r24    as MaxCnt (Constant value)
  20. #    Use r25    as LPixelBuf
  21. #    Use r26    as location within ColorTable32
  22. #    Use r27    as base address of ColorTable32
  23. #    Use r28    as BPP (that is, bytes per pixel)
  24.  
  25. #    r29    as RightEdge
  26. #    r30    as xtemp (integer)
  27.  
  28.  
  29. #    Note that the following are constants, and independent of xtemp.
  30.  
  31. #    First the integers
  32. #    MaxCnt    in r24
  33. #    LPixelBuf in r25. It changes but need only be loaded 1 time.
  34. #    Base address of ColorTable32 in r27
  35. #    BPP in r28
  36.  
  37. #    Now the floats    (Newly defined)
  38.  
  39. #    3.00 in f14
  40. #    Zr in f15.  It changes as Zr is recalculated.
  41. #    Use f16    as value of yRel.  This is constant for each line.
  42. #    Use f17    Zi.  It's initially yRel, but changes within loop.
  43. #    Use f18    as xRel. Only changes as DX is added for the next pixel.
  44. #    Use f19 as |Z2| Only for comparing with Limit.
  45. #    Use f20    This is scratch and used shortly for 2Zi.
  46. #    Delta x    in f21
  47. #    Two    in f22
  48. #    Limit    in f23
  49. #    Use f24    as Zr2.  This is also a temporary value
  50. #    Use f26 as Zr3.
  51.  
  52.  
  53.     .text
  54.     .sdreg    13
  55.     .global    UseLibP6
  56.     .align    4
  57. UseLibP6:
  58.     mflr    11
  59.     stw    11,4(1)    #Save return address
  60.     stwu    1,-80(1)      #Save stack pointer
  61.     fmr    16,1        #Transfer yrel from f1 to f16
  62.     lis    4,MaxCnt@ha
  63.     lwz    24,MaxCnt@l(4)        #MaxCnt in r24.
  64.     lis    4,LPixelBuf@ha
  65.     lwz    25,LPixelBuf@l(4)    #Get Location of LPixelBuf
  66.     lis    4,ColorTable32@ha
  67.     lwz    27,ColorTable32@l(4)    #Start of color table
  68.  
  69.     lis    4,BPP@ha
  70.     lwz    28,BPP@l(4)             #Number bytes per pixel
  71.     lis    4,Factor@ha
  72.     lfd    25,Factor@l(4)    #Get Factor into f25
  73.     lis    4,Two@ha
  74.     lfd    22,Two@l(4)    #Get Two into f22 as constant
  75.     lis    4,Limit@ha
  76.     lfd    23,Limit@l(4)    #Get Limit into f23 as constant
  77.  
  78.     fadd    14,22,22    #f14 is 4.
  79.     fadd    14,14,22    #f14 is 6.
  80.     fdiv    14,14,22    #f14 is 3.
  81.  
  82. #The above could have been done with a global definition of 3.000.
  83.  
  84.     li    30,0        #xtemp = 0.
  85.     fsub    15,22,22    #(float)xtemp = 0.
  86.     lis    4,XCenter@ha
  87.     lfd    10,XCenter@l(4)    #f10 = XCenter
  88.     fsub    15,15,10    #xRel = xRel - XCenter
  89.     fdiv    18,15,25    #xRel = xRel/Factor
  90.  
  91.     lis    4,DX@ha
  92.     lfd    21,DX@l(4)    #Get the real value of Delta x.
  93.     lis    4,RightEdge@ha
  94.     lwz    29,RightEdge@l(4)
  95.  
  96. Start:
  97.     fmr    15,18        #Initial value of Zr is xRel
  98.  
  99. #  The following line was moved before rather than after fmr f17,f16
  100. #  to give the fpu a break.
  101.     li    23,1        #Initialize CurCnt = 1
  102.     fmr    17,16        #yRel into f17 as initial Zi.
  103.     b    l3        #Check to see if to MaxCnt
  104. l2:
  105.     fmul    24,15,15    #Zr2 in f24
  106.     fmul    4,17,17    #Zi2 = Zi*Zi
  107.     fadd    19,24,4    #Zr2 + Zi2 -> f19
  108.     fcmpu    0,19,23    #Compare with Limit in f23.
  109.     ble    0,l6
  110.  
  111. #The following section is not very time-critical as it is only reached once.
  112. #for each pixel
  113.     cmpwi    0,28,2    #See if BPP < 2
  114.     blt    0,l8
  115. l7:
  116.     slwi    10,23,2    #4 times CurCnt for offset in ColorTable32
  117.     add    26,27,10    #Find location of pixel color in ColorTable32
  118.     lwz    11,0(26)    #Get ARGB from ColorTable
  119.     stw    11,0(25)    #Store color in LPixelBuf
  120.     addi    25,25,4    #Point to next location in LPixelBuf
  121.     b    l1
  122. l8:    andi.    3,23,65535    #Prep Color as UWORD for PlotIt
  123.     bl    PlotIt
  124. l9:    b    l1
  125. l6:
  126.  
  127.  
  128.     fmul    20,4,14    #Zi2*3 -> f20
  129.      fmul    27,24,14    #3*Zr2 -> f27
  130.     fsub    20,24,20    #Zr2 - 3*Zi2 -> f20
  131.     fsub    27,27,4    #(3Zr2 - Zi2) -> f27
  132.     fmul    20,20,15    #Zr*(Zr2 - 3Zi2) -> f20 = Zr3
  133.  
  134.     fmul    27,27,17    #Zi*(3Zr2 - Zi2) -> f27 = Zi3
  135.  
  136.     fmul    28,27,27    #Zi3*Zi3
  137.     fmul    29,20,20    #Zr3*Zr3
  138.     fmul    30,20,27    #Zr3*Zi3
  139.     fsub    29,29,28    #Zr3*Zr3 - Zi3*Zi3 = Zr6
  140.     fmul    17,30,22    #2*Zr3*Zi3 = Zi
  141.  
  142. #    fmr    24,29
  143.  
  144.  
  145.     fadd    15,18,29    #New Zr = xRel + Zr2
  146.     addi    23,23,1    #Increment CurCnt
  147.     fadd    17,16,17    #Zi = Zi + yRel
  148.  
  149. l3:
  150.     cmpw    0,23,24    #See if CurCnt < MaxCnt
  151.     blt    0,l2        #Repeat until MaxCnt reached
  152.  
  153.     cmpwi    0,28,2    #See if BPP < 2
  154.     blt    0,l11
  155. l10:
  156.  
  157.     lis    12,4
  158.     addi    12,12,-4
  159.     add    26,27,12    #Find location of pixel color
  160.     lwz    11,0(26)      #Get color
  161.  
  162.     stw    11,0(25)    #Store color in LPixelBuf
  163.     addi    25,25,4    #Point to next pixel in buffer
  164.     b    l1        #Was l12
  165. l11:
  166.     lis    11,1
  167.     addi    3,11,-1    #ffff into r3 for PlotIt
  168.     bl    PlotIt
  169. l1:
  170.     fadd    18,18,21    #Find new value of xRel (xRel = xRel + DX).
  171.     addi    30,30,1    #Increment xtemp.
  172.     cmpw    0,30,29    #See if to RightEdge
  173.  
  174.     blt    0,Start    #Repeat until row is done.
  175.     lis    4,LPixelBuf@ha
  176.     stw    25,LPixelBuf@l(4)  #New location in long pixel buffer
  177.     addi    1,1,80        #Balance Stack pointer
  178.     lwz    11,4(1)    #Get return address
  179.     mtlr    11
  180.  
  181.     blr
  182.     .type    UseLibP6,@function
  183.     .size    UseLibP6,$-UseLibP6
  184.  
  185.     .globl    MaxCnt
  186.     .globl    RightEdge
  187.     .globl    XCenter
  188.     .globl    Factor
  189.     .globl    Limit
  190.     .globl    Two
  191.     .globl    LPixelBuf
  192.     .globl    ColorTable32
  193.     .globl    BPP
  194.     .globl    DX
  195.     .globl    PlotIt
  196.  
  197.